<!DOCTYPE html PUBLIC>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>填写活动详情</title>
    <link href="$!webPath/css/template.css" rel="stylesheet" type="text/css"/>
    <link href="$!webPath/css/jquery-ui-1.8.22.custom.css" type="text/css" rel="stylesheet">
    <script src="$!webPath/js/jquery.min.js"></script>
    <script src="$!webPath/js/jquery-ui-1.8.21.js"></script>
    <script src="$!webPath/js/ajaxfileupload.js"></script>
    <script src="$!webPath/js/jquery.form1.js"></script>
    <script src="$!webPath/js/laydate/laydate.js"></script>
    <style type="text/css">
        label.error {
            color: #F00;
            margin-left: 3px;
        }

        input.error {
            border: 2px solid #F00;
        }
    </style>
</head>
<body>

<div class="header_nav">
    <iframe name="content_frame" src="$!webPath/admin/nav" marginwidth=0 marginheight=0  frameborder=0 width=100% height=80/></iframe>
    <div class="cont_right"><a href="$!webPath/login">注销</a></div>
</div>
<div class="cont">
    <h3 class="seth">编辑</h3>
    <div class="nav_list">
        <ul id="ul_table">
            <li><a href="$!webPath/admin/listAllActivity?size=10&page=0&type=0"><b>活动列表</b></a></li>
            <li><a href="javascript:void(0);" class="this"><b>编辑</b></a></li>
        </ul>
    </div>
    <div class="adddetail">
        <form method="post" name="theForm" id="theForm"  enctype="multipart/form-data">

            <div class="edit">
                <div class="setcont editul">
                    <ul class="set1">
                        <li class="setcont_bg">活动场地</li>
                        <li>
                            <input id="address" name="activityLocation" type="text" value="$!activityEntity.activityLocation" size="12">
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动名称</li>
                        <li>
                            <input name="activityName" id="activityName" type="text" value="$!activityEntity.activityName" size="12">
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动排序</li>
                        <li>
                            <input id="activitySequence" name="activitySequence" type="text" value="$!activityEntity.activitySequence" size="12">
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动类型</li>
                        <li>
                            <select id="activityType" name="activityType">
                                #if($!activityEntity.activityType==0)
                                <option value="0" selected>积分排名赛</option>
                                <option value="1">系列赛</option>
                                #elseif($!activityEntity.activityType==1)
                                <option value="0">积分排名赛</option>
                                <option value="1" selected>系列赛</option>
                                #else
                                <option value="0">积分排名赛</option>
                                <option value="1">系列赛</option>
                                #end
                            </select>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">是否被推荐</li>
                        <li>
                            #if($!activityEntity.isRecommend==0)
                            <input type="radio" name="isRecommend" value="0" checked/>未推荐活动
                            <input type="radio" name="isRecommend" value="1"/>推荐活动
                            #elseif($!activityEntity.isRecommend==1)
                            <input type="radio" name="isRecommend" value="0"/>未推荐活动
                            <input type="radio" name="isRecommend" value="1" checked/>推荐活动
                            #else
                            <input type="radio" name="isRecommend" value="0"/>未推荐活动
                            <input type="radio" name="isRecommend" value="1"/>推荐活动
                            #end

                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动开始时间</li>
                        <li>

                            <input id="activityTime" name="activityTime" class="laydate-icon" type="text" value="$!activityEntity.activityTime" size="30">
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动报名截止时间</li>
                        <li>
                            <input id="applyDeadLine" name="applyDeadLine" class="laydate-icon" type="text" value="$!activityEntity.applyDeadLine" size="30">
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">队伍报名上限</li>
                        <li>
                            <input id="teamUpperLimit" name="teamUpperLimit" type="text" value="$!activityEntity.teamUpperLimit" size="12">
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">是否为新活动</li>
                        <li>
                            #if($!activityEntity.isNew==0)
                            <input type="radio" name="isNew" value="0" checked/>否
                            <input type="radio" name="isNew" value="1"/>是
                            #elseif($!activityEntity.isNew==1)
                            <input type="radio" name="isNew" value="0"/>否
                            <input type="radio" name="isNew" value="1" checked/>是
                            #else
                            <input type="radio" name="isNew" value="0"/>否
                            <input type="radio" name="isNew" value="1"/>是
                            #end
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动状态</li>
                        <li>
                            <select id="activityStatus" name="activityStatus">
                                #if($!activityEntity.activityStatus==1)
                                <option value="0">--请选择--</option>
                                <option value="1" selected>报名中</option>
                                <option value="2">备战中</option>
                                <option value="3">活动结束</option>
                                #elseif($!activityEntity.activityStatus==2)
                                <option value="0">--请选择--</option>
                                <option value="1">报名中</option>
                                <option value="2" selected>备战中</option>
                                <option value="3">活动结束</option>
                                #elseif($!activityEntity.activityStatus==3)
                                <option value="0">--请选择--</option>
                                <option value="1">报名中</option>
                                <option value="2">备战中</option>
                                <option value="3" selected>活动结束</option>
                                #else
                                <option value="0" selected>--请选择--</option>
                                <option value="1">报名中</option>
                                <option value="2">备战中</option>
                                <option value="3">活动结束</option>
                                #end
                            </select>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg">活动介绍</li>
                        <li>
                            #set($activityIntroduction=$!utilsTools.transformStringNewLine("$!activityEntity.activityIntroduction"))
                            <textarea id="activityIntroduction" name="activityIntroduction" cols="50" rows="6">$!activityIntroduction</textarea>
                        </li>
                    </ul>
                    <ul class="set1">
                        <li class="setcont_bg"></li>
                        <li>
                            <!--商品图片上传 -->
                            <div class="tab_body" style="width: 500px">
                                <ul class="tabbody_ul">
                                    <li class="this">图</li>
                                </ul>
                                <div class="tabbodys" style="width: 498px;">
                                    <div class="tab_body_b" style="width: 500px;"></div>
                                    <div class="tab_body_a" style="width: 500px;">
                                        <div class="upload_pictures">
                                            <div class="upload_pictures_top">
                                                <div class="upload_pictures_top_img">

                                                    <img id="showImg" src="$!webPath/$!activityEntity.picPath" />

                                                </div>
                                            </div>
                                            <div class="upload_pictures_bottom">
                                                <ul>
                                                    <input type="hidden" name="pictureName" id="pictureName"/>
                                                    <input type="file" id="goodsPhoto" name="photo" style="opacity:1;position: static;" accept="image/jpg,image/jpeg,image/png">
                                                </ul>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>

            <div class="submit">
                <input type="hidden" name="activityId" value="$!activityEntity.id" >
                <span class="pad120">
                <input name="save" id="btn_submit" type="button" value="提交">
                </span>
            </div>
        </form>

    </div>
</div>
<script>
    $(function(){
        laydate({
            elem: '#activityTime',
            istime:true,
            format:'YYYY-MM-DD hh:mm:ss'
        })
        laydate({
            elem: '#applyDeadLine',
            istime:true,
            format:'YYYY-MM-DD hh:mm:ss'
        })
    })
    $('#goodsPhoto').change(function(){
        var $file = $(this);
        var fileObj = $file[0];
        var windowURL = window.URL || window.webkitURL;
        var dataURL;
        var $img = $("#showImg");

        if (fileObj && fileObj.files && fileObj.files[0]) {
            dataURL = windowURL.createObjectURL(fileObj.files[0]);
            $img.attr('src', dataURL);
        } else {
            dataURL = $file.val();
            var imgObj = document.getElementById("preview");
            // 两个坑:
            // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
            // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
            imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
            imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

        }
    })
    $('#btn_submit').click(function(){
        var adress=$('#address').val();
        var activityName=$('#activityName').val();
        var activitySequence=$('#activitySequence').val();
        var activityType=$('#activityType option:selected').val();
        var isRecommend=$('input:radio[name="isRecommend"]:checked').val();
        var activityTime=$('#activityTime').val();
        var applyDeadLine=$('#applyDeadLine').val();
        var teamUpperLimit=$('#teamUpperLimit').val();
        var isNew=$('input:radio[name="isNew"]:checked').val();
        var activityStatus=$('#activityStatus option:selected').val();
        var activityIntroduction=$('#activityIntroduction').val();
        $('#activityIntroduction').val(((activityIntroduction.replace(/<(.+?)>/gi,"&lt;$1&gt;")).replace(/ /gi,"&nbsp;")).replace(/\n/gi,"<br/>"));
        if(adress==''||activityName==''||activitySequence==''||activityType==''||activityTime==''||applyDeadLine==''||teamUpperLimit==''||isNew==''||activityStatus==0||activityIntroduction==''){
            alert('每一项都不能为空');
            return false;
        }
//        var get_data={
//            activityId:'$!activityEntity.id',
//            activityLocation:adress,
//            activityName:activityName,
//            activitySequence:activitySequence,
//            activityType:activityType,
//            activityTime:activityTime,
//            applyDeadLine:applyDeadLine,
//            teamUpperLimit:teamUpperLimit,
//            isNew:isNew,
//            activityStatus:activityStatus,
//            activityIntroduction:activityIntroduction
//        }
        $("#theForm").ajaxSubmit({
            url : "$!webPath/admin/add_activity",
            type : "post",
            success : function(data) {
                window.location.href = "$!webPath/admin/listAllActivity?size=10&page=0";
            },
            error : function(data) {
                alert('失败');
            }
        });
    })

</script>
</body>
</html>
